home *** CD-ROM | disk | FTP | other *** search
- Path: news.ecp.fr!stefania!dureta8
- From: dureta8@cti.ecp.fr (BIG ONE)
- Newsgroups: comp.lang.c
- Subject: gettimeofday() makes me mad !
- Date: 24 Feb 1996 18:20:33 GMT
- Organization: Ecole Centrale Paris, France
- Distribution: inet
- Message-ID: <4gnkth$4on@piston.ecp.fr>
- NNTP-Posting-Host: stefania.cti.ecp.fr
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hello all. If someone could help...
-
- COMPILER : gcc, or cc on a Unix system.
-
- PROBLEM : I'm trying to make a little program which must repeat an
- action every .2 second for example ( less than 1 sec anyway). time()
- wouldn't fit, so I searched and found the function gettimeofday() in
- <sys/time.h>. It gives the time elapsed since 1970 in seconds and
- microseconds. The problem is that when gettimeofday() is called several
- times, it finally hangs up ! My program looks like this :
-
- struct timeval t ;
- long useconds ;
-
- gettimeofday(&t) ;
- printf("%ld\n",(usecondes = t.tv_usec)) ;
-
- for (;;) {
- /* ... */ /*this part works fine */
- gettimeofday(&t) ;
- if (t.tv_usec > usecondes + 200000) {
- printf("%ld\n",(usecondes = t.tv_usec)) ;
- do_smthg() ;
- }
- }
-
- I tried it with time() instead of gettimeofday(), and there was no
- problem. Maybe there is another way ? Please help me before I commit
- suicide !
-
- --
- Alexandre Duret
- e-mail : dureta8@cti.ecp.fr
-